package com.ys.utils.base.j2se;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;


public class DateHandler {

	public static String []week = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
	
	/**
	 * 日期实体对象
	 */
	public static final class DateModel {
		public DateModel(int year, int month, int day, int week, long millisecond) {
			this.year = year;
			this.month = month;
			this.day = day;
			this.week = week;
			this.millisecond = millisecond;
		}

		private int year;
		private int month;
		private int day;
		private int week;
		private long millisecond;

		public long getMillisecond() {
			return millisecond;
		}

		public void setMillisecond(long millisecond) {
			this.millisecond = millisecond;
		}

		public int getYear() {
			return year;
		}

		public void setYear(int year) {
			this.year = year;
		}

		public String getMonth() {
			if (month < 10) {
				return "0" + month;
			}
			return "" + month;
		}

		public void setMonth(int month) {
			this.month = month;
		}

		public String getDay() {
			if (day < 10) {
				return "0" + day;
			}
			return "" + day;
		}

		public void setDay(int day) {
			this.day = day;
		}

		public int getWeek() {
			return week;
		}

		public void setWeek(int week) {
			this.week = week;
		}

		@Override
		public String toString() {
			return String.format("%s-%s-%s\t%s\t%s", year, month, day, week, millisecond);
		}
	}

	/**
	 * 获取add个月后的开启日期
	 * @param add
	 * @return
	 * @author 杨帅营
	 */
	public static long getBeginTime(int add) {
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.MONTH, add);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		calendar.set(Calendar.MILLISECOND, 0);
		return calendar.getTimeInMillis();
	}
	/**
	 * 获取日期实体 Calendar
	 */
	private static Calendar getCalendar(){
		Calendar claendar = Calendar.getInstance();
		claendar.setFirstDayOfWeek(Calendar.MONDAY);
		claendar.setTimeInMillis(claendar.getTimeInMillis());
		return claendar;
	}
	private static DateModel newInstansD(Calendar c){
		 return new DateModel(c.get(Calendar.YEAR),c.get(Calendar.MONTH)+1,c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.WEEK_OF_YEAR),c.getTimeInMillis());
	}
	/**
	 * 将TimeStamp 转换为形如 yyyyMMddHHmmssSSS
	 */
	public static String getMSecondFormatStr(Timestamp timeStamp) {
		long time = timeStamp.getTime();
		Date date = new Date(time);
		SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		return sf.format(date);
	}

	/**
	 * 将TimeStamp 转换为形如 yyyyMMddHHmmssSSS
	 */
	public static long getMSecondFormatLong(Timestamp timeStamp) {
		return Long.parseLong(getMSecondFormatStr(timeStamp));
	}
	
	/**
	 * 将long型date转换为yyyyMMddHHmmssSSS
	 */
	public static long getLongFormatDate(long time){
		SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		Date date = new Date(time);
		return Long.parseLong(sf.format(date));
	}
	/**
	 * 将 yyyy-MM-dd HH:mm:ss 转为 yyyyMMddHHmmss
	 * @param date
	 * @return
	 */
	public static long getLongFormatDate(String date){
		return getLongFormatDate(parseDatetime(date));
	}
	public static long getLongFormatDate(){
		SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
		Date date = new Date();
		return Long.parseLong(sf.format(date));
	}
	/**
	 * 将日期转为yyyyMMddHHmmss
	 */
	public static long getLongFormatDate(Date date){
		SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
		return Long.parseLong(sf.format(date));
	}
	/**
	 * 根据时间戳获取"yyyy-MM-dd HH:mm:ss.SSS"格式的字符串
	 * @param longTime 时间戳
	 * @return
	 */
	public static String getFormatMSecondFromStamp(long longTime){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		Date date = new Date(longTime);
		return sdf.format(date);
	}
	
	/**
	 * 获得时间戳的天 yyyyMMdd
	 */
	public static int getDay(long time){
		SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
		Date date = new Date(time);
		return Integer.parseInt(sf.format(date));
	}
	
	/**
	 * 获得时间戳的天 yyyy-MM-dd
	 */ 
	public static String getDay2(long time){
		Date date = new Date(time);
		return getDay2(date);
	}
	
	/**
	 * 获得时间戳的天 yyyy-MM-dd
	 */ 
	public static String getDay2(Date date){
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		return sf.format(date);
	}
	
	/**
	 * 获得当天日期
	 */
	public static int getDay(){
		SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
		return Integer.parseInt(sf.format(new Date()));
	}
	
	/**
	 * 取得7天前的日期
	 */
	public static int get7DayBeforDate(long time) {
		SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
		Calendar c = Calendar.getInstance();
		c.setTimeInMillis(time);
		c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) - 7);
		return Integer.parseInt(sf.format(c.getTime()));
	}
	
	/**
	 * 获取几天前的日期
	 * @param time
	 * @param day
	 * @return
	 */
	public static int getDayBeforDate(long time,int day) {
		SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
		Calendar c = Calendar.getInstance();
		c.setTimeInMillis(time);
		c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) - day);
		return Integer.parseInt(sf.format(c.getTime()));
	}
	/**
	 * 返回date日期当月最后一天的 23:59:59
	 * @param date
	 * @return
	 */
	public static long getEndPointOfMonth(Date date){
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.MONTH, 1);
		cal.set(Calendar.DAY_OF_MONTH, 1);
		cal.add(Calendar.DAY_OF_MONTH, -1); //last day of that month
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		return cal.getTimeInMillis();
	}
	
	/**获取指定日期当天的截止时间的时间戳:23:59:59.999
	 * @param date
	 * @return
	 */
	public static long getEndPointOfDay(Date date){
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		cal.set(Calendar.MILLISECOND, 999);
		return cal.getTimeInMillis();
	}
	
	/**
	 * 返回date日期当月的第一天的00:00:00时间
	 * @param date
	 * @return
	 */
	public static long getInitialPointOfMonth(Date date){
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.DAY_OF_MONTH, 1);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		return cal.getTimeInMillis();
	}
	
	/**
	 * 得到日期所在月的第一天  格式:20150209
	 */
	public static int getFirstDayOfMonth(Date date){
		return getDay(getInitialPointOfMonth(date));
	}
	
	/**
	 * 得到日期所在月的最后一天  格式:20150209
	 */
	public static int getLastDayOfMonth(Date date){
		return getDay(getEndPointOfMonth(date));
	}
	
	/**
	 * 得到制定日期上个月的最后一天此时的时间戳
	 */
	public static long getEndDayOfLastMonth(Date date){
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.MONTH, 0);
		cal.set(Calendar.DAY_OF_MONTH, 1);
		cal.add(Calendar.DAY_OF_MONTH, -1); //last day of that month
		return cal.getTimeInMillis();
	}
	
	/**
	 * 根据pattern将int类型转换为型时间表示格式
	 * eg: int d=20150209 pattern='yyyyMMdd' resutrn value是 Date 时间：'2015-02-09 00:00:00' 
	 * @param date
	 * @param pattern
	 */
	public static Date convertIntToDate(int date, String pattern) throws ParseException{
		return new SimpleDateFormat(pattern).parse(String.valueOf(date));
	}
	
	/**
	 * 返回从今天开始的加了n天以后的日期的23:59:59，
	 * 如果是负数就是今天以前的日期，如n=-1就返回昨天23:59:59时间
	 * @param n
	 * @return
	 */
	public static long addNDaysFromTodayEndPoint(int n){
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		cal.add(Calendar.DAY_OF_MONTH, n);
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		return cal.getTimeInMillis();
	}
	
	/**
	 * 返回从今天开始的加了n天以后的日期的00:00:00，
	 * 如果是负数就是今天以前的日期，如n=-1就返回昨天00:00:00时间
	 * @param n
	 * @return
	 */
	public static long addNDaysFromTodayInitialPoint(int n){
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		cal.add(Calendar.DAY_OF_MONTH, n);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		return cal.getTimeInMillis();
	}
	
	/**
	 * 返回从某天开始的加了n天以后的日期的00:00:00
	 * 如果是0 则是那天   如果是负数 则返回那天之前的00:00:00的时间
	 * @param time   时间戳
	 * @param n      距离的天数
	 * @return
	 */
	public static long addNDaysFromSomeDayInitialPoint(long time, int n){
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date(time));
		cal.add(Calendar.DAY_OF_MONTH, n);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		return cal.getTimeInMillis();
	}
	
	/**
	 * 得到N天的天数（格式：20150209）
	 */
	public static int addNDays4Today2Day(int n){
		return getDay(addNDaysFromTodayInitialPoint(n));
	}
	
	/**
	 * 取得前day天的日期数组
	 */
	public static List<Integer> getDayBeforDateArr(long time, int day){
		SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
		List<Integer> arr = new ArrayList<Integer>();
		Calendar c = Calendar.getInstance();
		c.setTimeInMillis(time);
		c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) - 7);
		for(int i=1; i<=day; i++){
			c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) + 1);
			arr.add(Integer.parseInt(sf.format(c.getTime())));
		}
		return arr;
	}
	
	/**
	 * 获取今天最后时间的时间戳       时间未精确到毫秒.建议使用getTodayLastTime 方法
	 * 结束时间yyyy-MM-dd 23:59:59
	 */
	@Deprecated
	public static long getToDayLastTime(long time) {
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(time);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		cal.add(Calendar.DAY_OF_MONTH, 1);
		cal.add(Calendar.SECOND, -1);
		return cal.getTime().getTime();
	}

    /**
     * 获取今天最后时间的时间戳  时间未精确到毫秒.建议使用getTodayLastTime 方法
     * 结束时间yyyy-MM-dd 23:59:59
     */
	@Deprecated
    public static long getToDayLastTime() {
        return getToDayLastTime(System.currentTimeMillis());
    }
    
    /**
     * 获取今天最后时间的时间戳 ,精确到毫秒
     * 结束时间yyyy-MM-dd 23:59:59
     */
    public static long getTodayLastTime() {
        return getTodayLastTime(System.currentTimeMillis());
    }
    
    /**获取今天的开始时间(yyyy-MM-dd 00:00:00.000的时间戳)
     * @return 
     */
    public static long getTodayStartTime(){
    	return getDayStartTime(System.currentTimeMillis());
    }
    
    /**获取指定日的开始时间
     * @param time
     * @return
     */
    public static long getDayStartTime(long time){
    	 Calendar cal = Calendar.getInstance();
         cal.setTimeInMillis(time);
         cal.set(Calendar.HOUR_OF_DAY, 0);
         cal.set(Calendar.MINUTE, 0);
         cal.set(Calendar.SECOND, 0);
         cal.set(Calendar.MILLISECOND, 0);
         return cal.getTimeInMillis();
    }
    
    /**
     * 获取今天最后时间的时间戳       
     * 结束时间yyyy-MM-dd 23:59:59,精确到毫秒
     */
    public static long getTodayLastTime(long time){
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(time);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.add(Calendar.DAY_OF_MONTH, 1);
        cal.add(Calendar.SECOND, -1);
        return cal.getTime().getTime();
    }
	
	/**
	 *  取得时间中的特定field值,eg: 2015-03-08 22:01:02 取得 MM 为 03 
	 * @param dateTime eg: 12345678901234
	 * @param pattern eg: "yyyy" | "MM" | "dd" | "HH" | "mm" | 'ss'
	 */
	public static int getCalendarField(long dateTime, String pattern, int defVal){
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date(dateTime));
		if(pattern.equals("yyyy")){
			return cal.get(Calendar.YEAR);
		}
		else if(pattern.equals("MM")){
			return cal.get(Calendar.MONTH);
		}
		else if(pattern.equals("dd")){
			return cal.get(Calendar.DAY_OF_MONTH);
		}
		else if(pattern.equals("HH")){
			return cal.get(Calendar.HOUR_OF_DAY);
		}
		else if(pattern.equals("mm")){
			return cal.get(Calendar.MINUTE);
		}
		else if(pattern.equals("ss")){
			return cal.get(Calendar.SECOND);
		}
		else{
			return defVal;
		}
	}

	/**
	 * 得到yyyy-MM-dd格式的日期
	 * 
	 * @param date
	 * @return
	 */
	public static String getYear_Month_Day(Date date) {
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		return format.format(date);
	}
	
	/**
	 * 比较当前时间与给定时间的大小
	 * @param time
	 * @param minutes
	 * @return
	 * @throws Exception
	 */
	public static boolean compareDate(String time,int minutes){
		boolean b = false;
	    Date   nows=new   Date();  
	    Date date = parseDatetime(time);		
		long   minms=nows.getTime()-(date.getTime()+minutes*60*1000); 
		if (minms >= 0){
		   b=true;
		}			   
		 return b;
	}
	
	/**
	 * 将字符串转为yyyy-MM-dd HH:mm:ss格式的Date对象
	 * @param date
	 * @return
	 */
	public static Date parseDatetime(String date){
		SimpleDateFormat t = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			Date s = t.parse(date);
			return s;
		} catch (ParseException e) {
			Logger.error("",e);
			return null;
		} 
	}

	/**
	 * 得到yyyy-MM-dd HH:mm:ss格式的日期
	 * 
	 * @param date
	 * @return
	 */
	public static String getDateString(Date date) {
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return format.format(date);
	}
	
	/**
	 * 得到相应格式的日期
	 * 
	 * @param date
	 * @param format  yyyy-MM-dd HH:mm:ss
	 * @return
	 */
	public static String getDateString(Date date,String format) {
		DateFormat dateFormat = new SimpleDateFormat(format);
		return dateFormat.format(date);
	}
	
	/**
	 * 获取上一周时间
	 */
	public static long getLastWeek(long time) {
		Calendar c = Calendar.getInstance();
		c.setTimeInMillis(time);
		c.add(Calendar.WEEK_OF_YEAR, -1);
		return c.getTime().getTime();
	}
	
	/**
	 * 获取当前月份  yyyyMM格式
	 */
	public static int getDayOfMonth(){
		DateFormat format = new SimpleDateFormat("yyyyMM");
		Date date = new Date();
		return Integer.parseInt(format.format(date));
	}
	
	/**
	 * 获取指定时间的月份  yyyyMM格式
	 */
	public static int getDayOfMonth(long time){
		DateFormat format = new SimpleDateFormat("yyyyMM");
		Date date = new Date(time);
		return Integer.parseInt(format.format(date));
	}
	/**
	 * 获取指定时间的月份 yyyyMM格式  传1为下月  -1为上一月
	 * @return
	 */
	public static int getDayOfMonth(int n){
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MONTH, n);
        return getDayOfMonth(cal.getTimeInMillis());
	}
	
	/**
	 * 获取本周的第一天
	 * @return
	 */
	public static int getThisWeekFirstDay(long time){
		Calendar claendar = Calendar.getInstance();
		claendar.setFirstDayOfWeek(Calendar.MONDAY);
		claendar.setTimeInMillis(time);
		claendar.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
		return getDay(claendar.getTimeInMillis());
	}
	
	/**
	 * 获取指定时间所在周的最后一天 23:59:59 的时间
	 * @return
	 */
	public static long getWeekLastDay(long time){
		Calendar claendar = Calendar.getInstance();
		claendar.setFirstDayOfWeek(Calendar.MONDAY);
		claendar.setTimeInMillis(time);
		claendar.set(Calendar.HOUR_OF_DAY, 23);
		claendar.set(Calendar.MINUTE, 59);
		claendar.set(Calendar.SECOND, 59);
		claendar.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY);
		return claendar.getTimeInMillis();
	}
	
	/**
	 * 根据指定时间返回 年和周
	 * 
	 * @param time
	 *            返回数组year=int[0] week=year[1]
	 * @return
	 */
	public static int[] getYearAndWeek(long time) {
		if (time <= 0) {
			return new int[] { 0, 0 };
		}
		Calendar c = Calendar.getInstance();
		c.setTimeInMillis(time);
		int year = Integer.parseInt(new SimpleDateFormat("yyyy").format(time));
		int month = Integer.parseInt(new SimpleDateFormat("MM").format(time));

		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(time);
		calendar.setFirstDayOfWeek(Calendar.MONDAY);// 设置周一为一星期的第一天
		int week = calendar.get(Calendar.WEEK_OF_YEAR);
		if (month == 12 && week == 1) {
			year++;
		}
		int[] yw = { year, week };
		return yw;
	}
	
	/**
	 * 获得当前时间距今天结束剩余多少秒
	 * 2015年11月13日 
	 * @return
	 * @throws ParseException
	 * Long
	 */
	public static int getSecond() throws ParseException{
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date sDate = df.parse(getDateString(new Date()));
		Date eDate = df.parse(DateHandler.getYear_Month_Day(new Date())+" 23:59:59:999");
		return (int)((eDate.getTime() - sDate.getTime()) / (1000));
	}
	/**
	 * 获取当日23:59:59:999 毫秒数
	 * 2015年11月13日 
	 * @return
	 * @throws ParseException
	 * Long
	 */
	public static Long getLongTime(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		long time = 0;
		try {
			time = sdf.parse(DateHandler.getYear_Month_Day(new Date())+" 23:59:59:999").getTime();
			return time;
		} catch (ParseException e) {
			Logger.error("时间转换异常",e);
			return 0L;
		}
		
	}
	
	/**
	 * 从传入时间戳获取年
	 * 2015年11月16日 
	 * @author 徐舒飞
	 * @return
	 */
	public static int getYear(Date date) {
	    Calendar ca = Calendar.getInstance();
	    ca.setTime(date);
	    int year = ca.get(Calendar.YEAR);
	    return year;
	}
	
	/**
	 * 从传入时间戳获取月
	 * 2015年11月16日 
	 * @author 徐舒飞
	 * @return
	 */
	public static int getMonth(Date date) {
		Calendar ca = Calendar.getInstance();
		ca.setTime(date);
		int month = ca.get(Calendar.MONTH) + 1;
		return month;
	}
	
	/**
	 * 从传入时间戳获取日
	 * 2015年11月16日 
	 * @author 徐舒飞
	 * @return
	 */
	public static int getDay(Date date) {
		Calendar ca = Calendar.getInstance();
		ca.setTime(date);
		int day = ca.get(Calendar.DAY_OF_MONTH);
		return day;
	}
	
	/**
	 * 获取当前时间的小时(24)
	 * @return
	 * @author john.(gongjie@xiu8.com)
	 * @date 2016年11月18日 上午11:15:15
	 */
	public static int getHour(){
		return Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
	}
	
	/**
	 * 根据传入时间戳，获取当前时间的小时(24)
	 * @param transId  时间戳
	 * @return 当前小时数
	 */
	public static int getHourByTransId(long transId){
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date(transId));
		return cal.get(Calendar.HOUR_OF_DAY);
	}
	
	/**
	 * 功能描述：返回分
	 *
	 * @param date
	 *            日期
	 * @return 返回分钟
	 */
	public static int getMinute(Date date) {
		Calendar cal = Calendar.getInstance();
		cal = Calendar.getInstance();
		cal.setTime(date);
	    return cal.get(Calendar.MINUTE);
	}
	
	/**
	 * 获取本周日期实体
	 * @param isAddYear true：进行跨年处理(建议使用true)
	 * @return
	 */
	public static DateModel getThisWeek(boolean isAddYear){
		if(isAddYear){
			DateModel now=newInstansD(catchYear(getCalendar()));
			return now;
		}else{
			DateModel now=newInstansD(getCalendar());
			return now;
		}
		
	}
	
	/**
	 * 获取上周日期实体
	 * @param isAddYear true：进行跨年处理(建议使用true)
	 * @return
	 */
	public static DateModel getLastWeek(boolean isAddYear){
		if(isAddYear){
			Calendar c=getCalendar();
			c.add(Calendar.WEEK_OF_YEAR, -1);
			catchYear(c);
			return newInstansD(c);
		}else{
			Calendar c=getCalendar();
			c.add(Calendar.WEEK_OF_YEAR, -1);
			return newInstansD(c);
		}
		
	}
	
	/**
	 * 跨年处理
	 * @param c
	 */
	public static Calendar catchYear(Calendar c){
		int month =c.get(Calendar.MONTH);
		if(month==Calendar.DECEMBER){
			//12月
			if(c.get(Calendar.WEEK_OF_YEAR)==1){
				c.add(Calendar.YEAR,1);
			}
		}
		return c;
	}
	
	/**
	 * 根据字符串获取毫秒日期
	 * 2016年1月7日 
	 * @param date
	 * @return
	 * @throws ParseException
	 * long
	 */
	public static long getTimeStamp(String date) throws ParseException{
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date longDate = df.parse(date);
		return longDate.getTime();
		
	}
	/**
	 * 获取当天   00:00:00毫秒日期
	 * 2016年1月7日 
	 * @deprecated 已过时，建议使用{@link DateHandler#getTodayStartTime()}
	 * @author jingwei@xiu8.com
	 * @return
	 * @throws ParseException
	 * long
	 */
	public static long getTodayTimeStamp() throws ParseException{
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date longDate = df.parse(getYear_Month_Day(new Date())+"  00:00:00");
		return longDate.getTime();
	}
	
	public static String getChDateString(String date){
		Date d = parseDatetime(date);
		Calendar cal=Calendar.getInstance();
		cal.setTime(d);
		StringBuffer s = new StringBuffer();
		s.append(cal.get(Calendar.YEAR)).append("年").append(cal.get(Calendar.MONTH)+1).append("月").append(cal.get(Calendar.DAY_OF_MONTH)).append("日");
		return s.toString();
	}
	
	public static Date getDateByTimeStamp(long time){
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(time);
		return calendar.getTime();
	}
	
	/**
	 * 获取离这个月的某月，第一天和最后一天
	 * @param pattern 要返回的日期的格式，默认是yyyy-MM-dd
	 * @param interval 离这个月的前几个月，如-1上个月，1下个月
	 * @return 某月，第一天和最后一天
	 * <p>
	 * 例子：例如这个月是2015年7月，getMonthFisrtLastDay(null,-1),返回['2015-06-01','2015-06-30']
	 * </p>
	 */
	public static String[] getMonthFisrtLastDay(String pattern, int interval) {
		if (Strings.isBlank(pattern))
			pattern = "yyyy-MM-dd";
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		Calendar cal = Calendar.getInstance();
		//下面可以设置月份，注：月份设置要减1，所以设置1月就是1-1，设置2月就是2-1，如此类推
		// cal.set(Calendar.MONTH, 1-1);
		//调到上个月
		cal.add(Calendar.MONTH, interval);
		//得到一个月最最后一天日期(31/30/29/28)
		int MaxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
		//按你的要求设置上月最后时间
		cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), MaxDay, 23, 59, 59);
		//按格式输出
		String lastMonthDay = sdf.format(cal.getTime());
		int minDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
		cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), minDay, 0, 0, 0);
		String firstMonthDay = sdf.format(cal.getTime());
		String[] arr = new String[2];
		arr[0] = firstMonthDay;
		arr[1] = lastMonthDay;
		return arr;
	}
	
	/**获取指定天数后的日期（格式：yyyy-MM-dd 00:00:00.000）
	 * @param days
	 * @return
	 */
	public static Date getDate(int days){
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DAY_OF_MONTH, days);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND, 0);
		return cal.getTime();
	}
	
	/**
	 * 为今天增加n天，n为负数，则得到今天之前的天
	 * @return yyyy-MM-dd格式的日期
	 */
    public static String addNdayforToday(int n){
    	long addDate = addNDaysFromTodayInitialPoint(n);
    	SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
    	Date date = new Date(addDate);
    	return sf.format(date);
	}
    
    /**
	 * 返回从今天开始的加了n小时以后的日期的yyyy-MM-dd HH:mm:ss:SSS，
	 * @param n
	 * @return
	 */
	public static String addNHoursFromToday(int n){
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		cal.add(Calendar.HOUR_OF_DAY, n);
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
    	Date date = new Date(cal.getTimeInMillis());
    	return sf.format(date);
	}
	
	/**
	 * 方法: getAllTheDayOfMonth <br>
	 * 描述: 获取指定日期月份的所有日期 <br>
	 * 作者: hailong@xiu8.com<br>
	 * 时间: 2016年10月18日 下午7:01:20
	 * @param date	
	 * @return	[20161001, 20161002, 20161003...]
	 */
	public static List<Integer> getAllTheDayOfMonth(Date date) {
		List<Integer> list = new ArrayList<Integer>();
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.set(Calendar.DATE, 1);
		int month = cal.get(Calendar.MONTH);
		while(cal.get(Calendar.MONTH) == month){
			list.add(getDay(cal.getTime().getTime()));
			cal.add(Calendar.DATE, 1);
		}
		return list;
	}
	
	/**
	 * 方法: getDaysOfMonth <br>
	 * 描述: 获取指定日期月份的天数 <br>
	 * 作者: hailong@xiu8.com<br>
	 * 时间: 2016年10月18日 下午7:01:20
	 * @param date	
	 * @return	天数
	 */
	public static int getDaysOfMonth(Date date)  
	{  
	    Calendar a = Calendar.getInstance();
	    a.setTime(date);
	    a.set(Calendar.DATE, 1);//把日期设置为当月第一天  
	    a.roll(Calendar.DATE, -1);//日期回滚一天，也就是最后一天  
	    return a.get(Calendar.DATE);  
	}
	
	
	/**
	 * 获取当天是一周的第几天    
	 * @param date
	 * @return 返回1是周一  7是周日
	 */
	public static int getDayOfWeek(Date date) {
		Calendar a = Calendar.getInstance();
		a.setTime(date);
		a.add(Calendar.DATE, -1);
		return a.get(Calendar.DAY_OF_WEEK);
	}
	
	/**
	 * 获取添加N天的日期
	 * @param day
	 * @return
	 */
	public static long getDateAddNDays(int day) {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DATE, day);
		return cal.getTimeInMillis();
	}
	
	/**
	 * 月份加减返回月份
	 * @param date  201612
	 * @param n  1
	 * @return  201701
	 */
	public static int addMonth(int date,int n){
		Calendar a = Calendar.getInstance();
		a.set(Calendar.YEAR, date/100);
		//月份 0表示1月  11表示12月
		a.set(Calendar.MONTH, date%100-1);
		System.out.println(a.getTime());
		a.add(Calendar.MONTH, n);
		return getDayOfMonth(a.getTime().getTime());
	}
	
	/**
	 * 2个月份之间差几个月
	 * @param date1  201701
	 * @param date2  201612
	 * @return  1
	 */
	public static int monthInterval(int date1,int date2){
		int year1 =  date1/100;
		int year2 =  date2/100;
		int month1 = date1%100;
		int month2 = date2%100;
		return (year1 - year2 )*12+(month1 - month2);
	}
	
	/**
	 * 转换任意时间格式
	 * @param dateTime    将要准换的时间，如："2017-01-01 10:10:21"</br>
	 * @param originTime  原始的时间格式：如："yyyy-MM-dd HH:mm:ss"</br>
	 * @param targetTime  目标的时间格式：如："yyyy年MM月dd日  HH:mm:ss"</br>
	 * @return  "2017年01月01日  10:10:21"
	 */
	public static String formatTime(String dateTime,String originTime,String targetTime){
		SimpleDateFormat stf = new SimpleDateFormat(originTime);
		SimpleDateFormat stf2 = new SimpleDateFormat(targetTime);
		Date parseDate=null;
		try {
			parseDate = stf.parse(dateTime);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return stf2.format(parseDate);
	}
	/**
	 * 那天0点的时间戳
	 * @param day  20170522
	 * @return
	 */
	public static long getTime(int day){
		SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
		Date longDate = null;
		try {
			longDate = df.parse(""+day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return longDate.getTime();
	}
	
	/**
	 * 时间相减得到天数
	 * @param beginDate   20170522
	 * @param endDate   20170531
	 * @return
	 */
	public static long getDaySub(int beginDate,int endDate) {
        long day=0;
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");    
        Date begin;
        Date end;
        try
        {
        	begin = format.parse(beginDate+"");
        	end= format.parse(endDate+"");    
            day=(end.getTime()-begin.getTime())/(24*60*60*1000);    
        } catch (ParseException e)
        {
            e.printStackTrace();
        }   
        return day;
    }
	
	/**
	 * 获取before前的日期（不包含今天）
	 * 
	 * @param time
	 * @param before
	 * @return yyyyMMdd
	 */
	public static int getDayBeforeDate(long time, int before) {
		SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
		Calendar c = Calendar.getInstance();
		c.setTimeInMillis(time);
		c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) - before);
		return Integer.parseInt(sf.format(c.getTime()));
	}
	
	/**
	 * 将long型date转换为HHmmss(时分秒)
	 */
	public static long getFormatDate(long time){
		SimpleDateFormat sf = new SimpleDateFormat("HHmmss");
		Date date = new Date(time);
		return Long.parseLong(sf.format(date));
	}
	
	/**
	 * 将字符串转换date
	 * @param time
	 * @param format
	 * @return
	 */
	public static Date getFormatDate(String time, String format) {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		// 解析时间 2016-01-05T15:09:54Z
		Date date = null;
		try {
			date = sdf.parse(time);
		} catch (ParseException e) {
			Logger.error("时间转换异常",e);
		}
		return date;
	}
	
	   /**
     * 函数功能描述:UTC时间转本地时间格式
     * @param utcTime UTC时间
     * @param utcTimePatten UTC时间格式
     * @param localTimePatten   本地时间格式
     * @return 本地时间格式的时间
     * eg:utc2Local("2017-06-14 09:37:50.788+08:00", "yyyy-MM-dd HH:mm:ss.SSSXXX", "yyyy-MM-dd HH:mm:ss.SSS")
     */
    public static String utc2Local(String utcTime, String utcTimePatten, String localTimePatten) {
        SimpleDateFormat utcFormater = new SimpleDateFormat(utcTimePatten);
        utcFormater.setTimeZone(TimeZone.getTimeZone("UTC"));//时区定义并进行时间获取
        Date gpsUTCDate = null;
        try {
            gpsUTCDate = utcFormater.parse(utcTime);
        } catch (ParseException e) {
            e.printStackTrace();
            return utcTime;
        }
        SimpleDateFormat localFormater = new SimpleDateFormat(localTimePatten);
        localFormater.setTimeZone(TimeZone.getDefault());
        String localTime = localFormater.format(gpsUTCDate.getTime());
        return localTime;
    }
    
    /**
	 * 天加减返回天
	 * @param day 20171106
	 * @param n  1
	 * @return  20171107
	 */
	public static int addDay(int day, int n){
		Calendar a = Calendar.getInstance();
		a.set(Calendar.YEAR, day/10000);
		a.set(Calendar.MONTH, (day/100)%100-1);//月份 0表示1月  11表示12月
		a.set(Calendar.DATE, day%100);
		a.add(Calendar.DATE, n);
		return getDay(a.getTime().getTime());
	}
	
	/**
	 * 
	 * @param birth 20101111
	 * @return  天蝎座
	 */
	public static String getStar(int birth) {
		String star = "";
		long time = getTime(birth);
		Date birthDay = new Date(time);
		int month = getMonth(birthDay);
		int day = getDay(birthDay);
		if (month == 1 && day >= 20 || month == 2 && day <= 18) {
			star = "水瓶座";
		}
		if (month == 2 && day >= 19 || month == 3 && day <= 20) {
			star = "双鱼座";
		}
		if (month == 3 && day >= 21 || month == 4 && day <= 19) {
			star = "白羊座";
		}
		if (month == 4 && day >= 20 || month == 5 && day <= 20) {
			star = "金牛座";
		}
		if (month == 5 && day >= 21 || month == 6 && day <= 21) {
			star = "双子座";
		}
		if (month == 6 && day >= 22 || month == 7 && day <= 22) {
			star = "巨蟹座";
		}
		if (month == 7 && day >= 23 || month == 8 && day <= 22) {
			star = "狮子座";
		}
		if (month == 8 && day >= 23 || month == 9 && day <= 22) {
			star = "处女座";
		}
		if (month == 9 && day >= 23 || month == 10 && day <= 23) {
			star = "天秤座";
		}
		if (month == 10 && day >= 24 || month == 11 && day <= 22) {
			star = "天蝎座";
		}
		if (month == 11 && day >= 23 || month == 12 && day <= 21) {
			star = "射手座";
		}
		if (month == 12 && day >= 22 || month == 1 && day <= 19) {
			star = "摩羯座";
		}
		return star;
	}
	
	/**生日是否合法
	 * @param birth 生日：yyyyMMdd，如20180101
	 * @return -1=年份有误；-2=月份有误；-3=日期有误；1=合法生日
	 */
	public static int isValidBirth(int birth){
		Calendar instance = Calendar.getInstance();
		int year = birth / 10000;
		//出生年份不能超过当前年份
		if (year > instance.get(Calendar.YEAR)) {
			return -1;
		}
		int month = (birth / 100) % 100;
		if (month < 1 || month > 12) {
			return -2;
		}
		int day = birth % 100;
		instance.set(Calendar.YEAR, year);
		instance.set(Calendar.MONTH, month - 1);
		instance.set(Calendar.DAY_OF_MONTH, day);
		//判断日期是否合法(如：非闰年 月日 不能是2月29日等)
		if (year != instance.get(Calendar.YEAR) || month != (instance.get(Calendar.MONTH) + 1) || day != instance.get(Calendar.DAY_OF_MONTH)) {
			return -3;
		}
		return 1;
	}
	
	public static void main(String[] args) {
//		System.out.println(utc2Local("2017-09-12T09:10:16Z", "yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd HH:mm:ss"));
//		System.out.println(getDateString(new Date(), "yyyyMMddHHmm"));
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		cal.add(Calendar.MONTH, 0);
		cal.set(Calendar.DAY_OF_MONTH, 1);
		cal.add(Calendar.DAY_OF_MONTH, -1); //last day of that month
		long timeInMillis = cal.getTimeInMillis();
		System.out.println(timeInMillis);
		System.out.println(getDay(timeInMillis));
		long addNDaysFromSomeDayInitialPoint = addNDaysFromSomeDayInitialPoint(timeInMillis, -28+1);
		System.out.println(getDay(addNDaysFromSomeDayInitialPoint));
	}
	/**
	 * 取得当前日期的字符串表示,格式为 yyyy-MM-dd
	 *
	 * @return 返回日期的字符串表示
	 */
	public static int strDay2Int(String dayStr) {
		int day = 0;
		if(null!=dayStr && !"".equals(dayStr)) {
			String dayTemp = dayStr.replaceAll("-", "");
			day = Integer.parseInt(dayTemp);
		}
		return day;
	}

	/**
	 * 获取本周的开始时间
	 * @return
	 */
	public static Date getBeginDayOfWeek() {
		Date date = new Date();
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
		if (dayofweek == 1) {
			dayofweek += 7;
		}
		cal.add(Calendar.DATE, 2 - dayofweek);
		return getDayStartTime(cal.getTime());
	}

	/**
	 * 获取本周的结束时间
	 * @return
	 */
	public static Date getEndDayOfWeek(){
		Calendar cal = Calendar.getInstance();
		cal.setTime(getBeginDayOfWeek());
		cal.add(Calendar.DAY_OF_WEEK, 6);
		Date weekEndSta = cal.getTime();
		return getDayEndTime(weekEndSta);
	}


	/**
	 * 获取某个日期的开始时间
	 * @param d
	 * @return
	 */
	public static Timestamp getDayStartTime(Date d) {
		Calendar calendar = Calendar.getInstance();
		if(null != d) calendar.setTime(d);
		calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),    calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
		calendar.set(Calendar.MILLISECOND, 0);
		return new Timestamp(calendar.getTimeInMillis());
	}

	/**
	 * 获取某个日期的结束时间
	 * @param d
	 * @return
	 */
	public static Timestamp getDayEndTime(Date d) {
		Calendar calendar = Calendar.getInstance();
		if(null != d) calendar.setTime(d);
		calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),    calendar.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
		calendar.set(Calendar.MILLISECOND, 999);
		return new Timestamp(calendar.getTimeInMillis());
	}


	/**
	 * 获取上周的开始时间
	 * @return
	 */
	public static Date getBeginDayOfLastWeek() {
		Date date = new Date();
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
		if (dayofweek == 1) {
			dayofweek += 7;
		}
		cal.add(Calendar.DATE, 2 - dayofweek - 7);
		return getDayStartTime(cal.getTime());
	}

	/**
	 * 获取上周的结束时间
	 * @return
	 */
	public static Date getEndDayOfLastWeek(){
		Calendar cal = Calendar.getInstance();
		cal.setTime(getBeginDayOfLastWeek());
		cal.add(Calendar.DAY_OF_WEEK, 6);
		Date weekEndSta = cal.getTime();
		return getDayEndTime(weekEndSta);
	}

	/**
	 * 根据字符时间转换
	 * @param str
	 * @return
	 * @throws Exception
	 */
	public static Date getDate(String str) throws Exception{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date sDate = sdf.parse(str);
		return sDate;
	}

	/**
	 * 根据时间转换字符
	 * @param date
	 * @return
	 * @throws Exception
	 */
	public static String getDate(Date date) {
		return getDate(date, "yyyy-MM-dd");
	}

	/**
	 * 将指定Date类型转换成指定格式的字符串,格式串参见类注释
	 *
	 * @param date 日期方式
	 * @param format 指定的格式,当format为NULL或空串时,<BR>
	 * 		  默认为 yyyy-MM-dd 格式
	 * @return 当date为NULL时,返回空串
	 */
	public static String getDate(Date date, String format) {

		String dtstr = "";
		if (date == null) {
			return dtstr;
		}

		if (format == null || "".equals(format.trim())) {
			format = "yyyy-MM-dd";
		}

		SimpleDateFormat sdf = new SimpleDateFormat(format);
		dtstr = sdf.format(date);
		return (dtstr == null ? "" : dtstr);

	}

	/**
	 * 功能：格式化时间为中文格式  例如：1分钟前
	 * @param time 字符串时间
	 * @return
	 */
	public static String getTimeReduce(String time) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String str = "";
		try {
			Date d1 = new Date();
			Date d2 = df.parse(time);
			long diff = d1.getTime() - d2.getTime();
			long days = diff / (1000 * 60 * 60 * 24);
			long hours = (diff - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
			long minutes = (diff - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);
			if (days > 0) {
				if (days > 7) {
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					str = sdf.format(d2);
				} else {
					if (days / 365 > 0) {
						str = days / 365 + "年前";
					} else {
						str = days + "天前";
					}
				}
			} else {
				if (hours > 0) {
					str = hours + "小时前";
				} else {
					if (minutes > 0) {
						str = minutes + "分钟前";
					} else {
						str = "刚刚";
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return str;
	}
	/**
	 * Java将Unix时间戳转换成指定格式日期字符串
	 * @param timestampString 时间戳 如："1473048265";
	 * @param formats 要格式化的格式 默认："yyyy-MM-dd HH:mm:ss";
	 *
	 * @return 返回结果 如："2016-09-05 16:06:42";
	 */
	public static String timeStamp2Date(String timestampString, String formats) {
		if (null==formats || "".equals(formats))
			formats = "yyyy-MM-dd HH:mm:ss";
		Long timestamp = Long.parseLong(timestampString) * 1000;
		String date = new SimpleDateFormat(formats).format(new Date(timestamp));
		return date;
	}

	/**
	 * 格式化unix时间戳
	 * @param timestampString
	 * @param formats
	 * @return
	 */
	public static String TimeStamp2Date(String timestampString, String formats) {
		if (StringUtils.isEmpty(formats))
			formats = "yyyy-MM-dd HH:mm:ss";
		Long timestamp = Long.parseLong(timestampString) * 1000;
		String date = new SimpleDateFormat(formats, Locale.CHINA).format(new Date(timestamp));
		return date;
	}

	/**
	 * 获取指定日期的当天的开始时间
	 * @param dateStr
	 * @return
	 * @throws ParseException
	 */
	public static long getDateBeginLong(String dateStr) throws ParseException{
		long unixtime = 0;
		if(StringHandler.isNotEmpty(dateStr)) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date date = sdf.parse(dateStr);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			calendar.set(Calendar.HOUR, 0);
			calendar.set(Calendar.MINUTE, 0);
			calendar.set(Calendar.SECOND, 0);
			calendar.set(Calendar.MILLISECOND, 0);
			unixtime = calendar.getTime().getTime();
		}
		return unixtime;
	}
	/**
	 * Java将Unix时间戳转换成指定格式日期字符串
	 * @param timestampString 时间戳 如："1473048265";
	 * @param formats 要格式化的格式 默认："yyyy-MM-dd HH:mm:ss";
	 *
	 * @return 返回结果 如："2016-09-05 16:06:42";
	 */
	public static String timeStamp2DateLong(String timestampString, String formats) {
		if (null==formats || "".equals(formats))
			formats = "yyyy-MM-dd HH:mm:ss";
		Long timestamp = Long.parseLong(timestampString);
		String date = new SimpleDateFormat(formats).format(new Date(timestamp));
		return date;
	}

	public static String getMinute(int number) {
		Calendar nowTime = Calendar.getInstance();
		nowTime.add(Calendar.MINUTE, number);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		return sdf.format(nowTime.getTime());
	}

	/**
	 * 获取当天剩余秒数
	 * @param type 1 毫秒 2 秒
	 * @return
	 */
	public static long dayMillSeconds(int type){
		LocalDateTime midnight = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
		long dayMillSeconds = 300;
		if(type==1){
			dayMillSeconds = ChronoUnit.MILLIS.between(LocalDateTime.now(),midnight);
		}else if(type==2){
			dayMillSeconds = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight);
		}
		return dayMillSeconds;
	}
}
